//
//  UIAlertController+BIZCategory.m
//  biz
//
//  Created by 边文辉 on 2017/3/17.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "UIAlertController+BIZCategory.h"

@implementation UIAlertController (BIZCategory)

+ (void)showAlertViewWithTitle:(NSString *)title message:(NSString *)msg cancelButtonTitle:(NSString *)clTitle confirmButtonTitle:(NSString *)cfTitle cancelBlock:(void (^)())clBlock confirmBlock:(void (^)())cfBlock
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
    
    if (clTitle.length) {
        [alert addAction:[UIAlertAction actionWithTitle:clTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            if (clBlock) clBlock();
        }]];
    }
    
    if (cfTitle.length) {
        [alert addAction:[UIAlertAction actionWithTitle:cfTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (cfBlock) cfBlock();
        }]];
    }
    
    
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alert animated:YES completion:nil];
}

+ (void)showAlertViewWithController:(UIViewController *)controller
                              title:(NSString *)title
                            message:(NSString *)msg
                  cancelButtonTitle:(NSString *)clTitle
                 confirmButtonTitle:(NSString *)cfTitle
                        cancelBlock:(void (^)())clBlock
                       confirmBlock:(void (^)())cfBlock
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
    
    if (clTitle.length) {
        [alert addAction:[UIAlertAction actionWithTitle:clTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            if (clBlock) clBlock();
        }]];
    }
    
    if (cfTitle.length) {
        [alert addAction:[UIAlertAction actionWithTitle:cfTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (cfBlock) cfBlock();
        }]];
    }
    
    if (controller) {
        [controller presentViewController:alert animated:YES completion:nil];
    }
}

@end
